<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>交互-树形图展开折叠</title>
</head>

<body>
  <div id="mountNode"></div>
  <script src="../build/g6.js"></script>
  <script>
    const data = {
      roots: [{
        children: [{
          children: [
            {
            }
          ]
        }, {
        }]
      }]
    };
    const tree = new G6.Tree({
      container: 'mountNode',
      width: 500,
      height: 500,
      fitView: 'cc',
      animate: true
    });
    tree.on('node:click', ev=>{
      const { item } = ev;
      const { collapsed } = item.getModel();
      if (collapsed) {
          tree.update(item, {
            collapsed: false,
          });
        } else {
          tree.update(item, {
            collapsed: true,
          });
        }
    });
    tree.read(data);
  </script>
</body>
</html>
